<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* id选择器的回顾应用 */
        
        #tex {
            border: 1px solid #ccc;
        }
    </style>
</head>

<body>
    <input type="text" value="邮箱/ID/手机号" id="tex">
    <script>
        //1.获取事件
        var tex = document.getElementById('tex');
        //2.注册事件
        //获得焦点事件
        tex.onfocus = function() {
                if (tex.value === '邮箱/ID/手机号') {
                    tex.value = '';
                }
                //文本框中输入的字变黑
                tex.style.color = 'blank';
                //文本框的背景颜色变为浅粉色
                tex.style.backgroundColor = '#f0d7e2';
            }
            //失去焦点事件
        tex.onblur = function() {
            if (tex.value === '') {
                tex.value = '邮箱/ID/手机号';
            }
            tex.style.color = '#ccc';
            tex.style.backgroundColor = '#fff';
        }
    </script>
</body>

</html>